DynamicContentLoader = {
		
		//private
		defaultPage: '/mapview',
		
		//private
		hashUrlMapping: [{hashUrl: '', requestUrl: 'default' },
		                 {hashUrl: '#/', requestUrl: 'default' },
		                 {hashUrl: '#/register', requestUrl: '/register' },
		                 {hashUrl: '#/friends', requestUrl: '/friends' },
		                 {hashUrl: '#/map', requestUrl: '/mapview' },
		                 {hashUrl: '#/user/username', requestUrl: '/user/' }
		                 ],
		
		initialize: function(){
			$(window).hashchange( DynamicContentLoader.processHashChange );
			$(window).trigger( 'hashchange' );
		},
		
		processHashChange: function(){
			var hash = location.hash;
			var regexUserProfile = '^#\/user\/([a-zA-Z0-9_.-]+)$'; // for #/user/USERNAME
			if(hash.match(regexUserProfile))
			{
				var requestUrl = hash.replace('#/user/', '/user/');
				DynamicContentLoader.loadContent(contextPath + requestUrl, "#content");
				return false;
			}
			
			$.each(DynamicContentLoader.hashUrlMapping, function(index, elem) {
				if(elem.hashUrl == hash) {
					if(elem.requestUrl === 'default')
						DynamicContentLoader.loadContent(contextPath + DynamicContentLoader.defaultPage, "#content");
					else
					{
						DynamicContentLoader.loadContent(contextPath + elem.requestUrl, "#content");
					}
					return false;
				}
			});
		},
		
		addMapping: function(hashUrl, requestUrl)
		{
			var mapping = {
					hashUrl: hashUrl,
					requestUrl: requestUrl
			};
			
			DynamicContentLoader.hashUrlMapping.push(mapping);
		},
		
		loadContent: function(requestUrl, targetElement, data){
			DynamicContentLoader.maskContentDiv();
			$(targetElement).load(requestUrl, data, function(responseText, textStatus, XMLHttpRequest){
				DynamicContentLoader.unmaskContentDiv();
			});
		},
		
		maskContentDiv: function(){
			$("#content-loading-mask").fadeIn('fast');
		},
		
		unmaskContentDiv: function(){
			$("#content-loading-mask").fadeOut('fast');
		}
};